﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"    
    xmlns:scott="clr-namespace:ScottIsAFool.WindowsPhone.Controls;assembly=ScottIsAFool.WindowsPhone"
    xmlns:adduplex="clr-namespace:AdDuplex;assembly=AdDuplex.AdControl.Silverlight"
    xmlns:adRotator="clr-namespace:AdRotator;assembly=AdRotator"
    xmlns:int="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:Behaviours="clr-namespace:Url2Ringtone.Behaviours"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:resources="clr-namespace:Url2Ringtone.Resources"
    xmlns:daniel="clr-namespace:DanielVaughan.Windows"
    xmlns:controlsPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls" 
    x:Class="Url2Ringtone.MainPage" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" 
    d:DataContext="{d:DesignData ../SampleData/MainViewModelSampleData.xaml}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
	toolkit:TiltEffect.IsTiltEnabled="True">   
	
	<phone:PhoneApplicationPage.FontFamily>
		<StaticResource ResourceKey="PhoneFontFamilyNormal"/>
	</phone:PhoneApplicationPage.FontFamily>
	<phone:PhoneApplicationPage.FontSize>
		<StaticResource ResourceKey="PhoneFontSizeNormal"/>
	</phone:PhoneApplicationPage.FontSize>
	<phone:PhoneApplicationPage.Foreground>
		<StaticResource ResourceKey="PhoneForegroundBrush"/>
	</phone:PhoneApplicationPage.Foreground>
	
	<toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>    

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <daniel:ProgressIndicatorProxy Text="{Binding ProgressText}" 
                                       Value="{Binding ProgressChanged}"
                                       IsIndeterminate="{Binding IsIndeterminate}"
                                       IsVisible="{Binding IsIndeterminate}"/>
        <controls:Pivot Title="{StaticResource AppName}" x:Name="pivotMain" VerticalAlignment="Top" Height="612">
    		<controls:Pivot.HeaderTemplate>
    			<DataTemplate>
    				<TextBlock Text="{Binding}" Style="{StaticResource PhoneTextAlmostLargeStyle}" Margin="12,0,-20,0"/>    		
    			</DataTemplate>
    		</controls:Pivot.HeaderTemplate>
    		<!--Pivot item one-->
    		<controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotRingtone, Mode=OneTime}">
    			<!--Double line list with text wrapping-->
    			<Grid>
    				<Grid.RowDefinitions>
    					<RowDefinition Height="100"/>
    					<RowDefinition Height="*"/>           	
    				</Grid.RowDefinitions>         
					
    				<StackPanel Orientation="Vertical" Grid.Row="0">
    					<StackPanel Orientation="Horizontal">
                            <toolkit:PhoneTextBox 
                                LengthIndicatorVisible="False" 
                                Hint="{Binding Source={StaticResource StringsManager}, Path=Strings.UrlHint, Mode=OneTime}" 
                                x:Name="txbxRingtoneUrl" 
                                Width="396" 
                                InputScope="Url" 
                                Text="{Binding CurrentItem.OriginalUrl, Mode=TwoWay}" 
                                KeyDown="txbxRingtoneUrl_KeyUp"
								ActionIcon="/Icons/clearboxicon.png"
								ActionIconTapped="txbxRingtoneUrl_ActionIconTapped">
                                <int:Interaction.Behaviors>
                                    <Behaviours:UpdateTextBindingOnPropertyChanged/>
                                </int:Interaction.Behaviors>
                            </toolkit:PhoneTextBox>
                            
    						<Button x:Name="btnGo" 
                                    Click="btnGo_Click" 
                                    IsEnabled="{Binding Text, Converter={StaticResource LengthToBool}, ElementName=txbxRingtoneUrl}" 
                                    Opacity="{Binding Text, Converter={StaticResource LengthToOpacity}, ElementName=txbxRingtoneUrl}" 
                                    Height="48" 
                                    Width="48">
    							<Button.Template>
    								<ControlTemplate>
    									<Image Height="48" 
                                               Width="48" 
                                               Source="{Binding IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=downloadringtone}"/>                   		
    								</ControlTemplate>                    	
    							</Button.Template>                     
    						</Button>
    					</StackPanel>    					
    				</StackPanel>

                    <StackPanel Orientation="Vertical" Grid.Row="1">
    				    <StackPanel Orientation="Vertical" 
                                    IsHitTestVisible="{Binding DownloadingMP3, Converter={StaticResource InvertBoolean}}" 
                                    Opacity="{Binding DownloadingMP3, Converter={StaticResource InvertedOpacityConverter}}">
                            <toolkit:PhoneTextBox LengthIndicatorVisible="False" 
                                                  Text="{Binding CurrentItem.RingtoneName, Mode=TwoWay}" 
                                                  Hint="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneName, Mode=OneTime}" 
                                                  x:Name="txbxRingtoneName" 
                                                  InputScope="Text" 
                                                  TextChanged="txbxRingtoneName_TextChanged">
                                <int:Interaction.Behaviors>
                                    <Behaviours:UpdateTextBindingOnPropertyChanged/>
                                </int:Interaction.Behaviors>
                            </toolkit:PhoneTextBox>
    					    <TextBlock Text="{Binding CurrentItem.ToneSizeString}" 
                                       Style="{StaticResource PhoneTextNormalStyle}" 
                                       Height="35" 
                                       Margin="20,0,0,0"/>
                            <CheckBox x:Name="chbxSaveRingtone" 
                                      Content="{Binding Source={StaticResource StringsManager}, Path=Strings.SaveRingtoneLocally, Mode=OneTime}" 
                                      IsChecked="{Binding CurrentItem.IsStoredLocally, Mode=TwoWay}"/>
    					    <MediaElement x:Name="ringtonePlayer" 
                                          AutoPlay="True" 
                                          CurrentStateChanged="ringtonePlayer_CurrentStateChanged"/>						    					
                        </StackPanel>
                        <TextBlock Text="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneInstructions, Mode=OneTime}" 
                                   Margin="12,10,0,0" 
                                   TextWrapping="Wrap" 
                                   Style="{StaticResource PhoneTextNormalStyle}"/>
                    </StackPanel>
    			</Grid>                
    		</controls:PivotItem>
 
    		<!--Pivot item two-->
            <controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotHistory, Mode=OneTime}"> 
    			<!--Triple line list no text wrapping-->
				<Grid>		
					<Grid.RowDefinitions>
						<RowDefinition Height="*"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>					
					<toolkit:MultiselectList Grid.Row="0" 
                                             x:Name="lbHistory" 
                                             Margin="0,0,-12,0" 
                                             ItemsSource="{Binding Items}" 
                                             SelectionChanged="lbHistory_SelectionChanged"
                                             Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=false}">
						<toolkit:MultiselectList.ItemTemplate>
							<DataTemplate>
	    						<StackPanel Margin="0,0,0,17" 
                                            VerticalAlignment="Top" 
                                            Tap="StackPanel_Tap">
	    							<TextBlock Text="{Binding RingtoneName}" 
                                               VerticalAlignment="Top" 
                                               TextWrapping="NoWrap"
                                               Margin="12,0,0,0" 
                                               Style="{StaticResource PhoneTextExtraLargeStyle}"/>
									<StackPanel Orientation="Horizontal" Margin="12,0,0,0">
										<Image Height="30" 
                                               VerticalAlignment="Top" 
                                               Source="{Binding Source={StaticResource viewModel}, Path=IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=appbar.save.rest}" 
                                               Width="30" 
                                               Visibility="{Binding IsStoredLocally, Converter={StaticResource VisibilityConverter}}" 
                                               Margin="0,-6,0,1"/>
	    								<TextBlock Text="{Binding OriginalUrl}" 
                                                   TextWrapping="NoWrap" 
                                                   Margin="0,-6,0,0" 
                                                   Style="{StaticResource PhoneTextSubtleStyle}" 
                                                   Width="406"/>
									</StackPanel>
	    						</StackPanel>
	    					</DataTemplate>
						</toolkit:MultiselectList.ItemTemplate>
					</toolkit:MultiselectList>	    			
					<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top"
								Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=false}">
						<Image Height="30" 
                               VerticalAlignment="Top" 
                               Source="{Binding IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=appbar.save.rest}" 
                               Width="30" 
                               Margin="0,-6,0,0"/>
                        <TextBlock Text="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneKey, Mode=OneTime}" 
                                   Style="{StaticResource PhoneTextSmallStyle}" 
                                   Margin="1,-4,12,0"/>
					</StackPanel>
                    <TextBlock VerticalAlignment="Top" 
                               HorizontalAlignment="Center" 
                               Text="{Binding Source={StaticResource StringsManager}, Path=Strings.NoItems, Mode=OneTime}" 
                               TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}"
                               Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=true}"/>
				</Grid>
    		</controls:PivotItem>

            <controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotAbout, Mode=OneTime}">
    			<Grid>
    				<StackPanel Orientation="Vertical" Margin="0,0,0,48">
	    				<TextBlock Style="{StaticResource PhoneTextNormalStyle}" 
                                   Height="62" 
                                   TextWrapping="Wrap" 
                                   Width="440" 
                                   VerticalAlignment="Top" 
                                   HorizontalAlignment="Left" 
                                   Margin="8,8,0,0" 
                                   Text="WebTone © ScottIsAFool (@scottisafool) 2011 Version 1.1.0" />			            
						<StackPanel Orientation="Horizontal">
                            <Button x:Name="btnEmail" 
                                    Content="{Binding Source={StaticResource StringsManager}, Path=Strings.EmailMe, Mode=OneTime}" 
                                    HorizontalAlignment="Left" 
                                    Margin="14,0,0,0" 
                                    VerticalAlignment="Top" 
                                    Width="207" 
                                    d:LayoutOverrides="HorizontalAlignment" 
                                    Click="btnEmail_Click" />
                            <Button x:Name="btnTwitter" 
                                    Content="{Binding Source={StaticResource StringsManager}, Path=Strings.MyTwitter, Mode=OneTime}" 
                                    Margin="0,0,14,0" 
                                    VerticalAlignment="Top" 
                                    HorizontalAlignment="Right" 
                                    Click="btnTwitter_Click" 
                                    Width="207" />
						</StackPanel>
                        <Button x:Name="btnWebsite" 
                                Content="{Binding Source={StaticResource StringsManager}, Path=Strings.MySite, Mode=OneTime}" 
                                VerticalAlignment="Top" 
                                Margin="14,0,0,0" 
                                Width="207" 
                                HorizontalAlignment="Left" 
                                Click="btnWebsite_Click" />
						<RichTextBox Width="420" HorizontalAlignment="Left">							
							<Paragraph>
                                <Run Text="{Binding Source={StaticResource StringsManager}, Path=Strings.GraphicsBy, Mode=OneTime}"/>
								<Hyperlink x:Name="linkMike" Click="linkMike_Click">Mike Hilton</Hyperlink>
							</Paragraph>
                            <Paragraph>
                                <Run Text="{Binding Source={StaticResource StringsManager}, Path=Strings.NotificationBoxText, Mode=OneTime}"/>
                                <Hyperlink x:Name="linkTomer" Click="linkTomer_Click">Tomer Shamam</Hyperlink>
                            </Paragraph>
                            <Paragraph/>
                            <Paragraph>                                
                                <Hyperlink x:Name="linkBlog" Click="linkBlog_Click">http://webtoneapp.wordpress.com</Hyperlink>
                            </Paragraph>
						</RichTextBox>						
					</StackPanel>
                    <Button x:Name="btnRate" 
                            Content="{Binding Source={StaticResource StringsManager}, Path=Strings.RateApp, Mode=OneTime}" 
                            VerticalAlignment="Bottom" 
                            Click="btnRate_Click" 
                            Margin="0,0,0,-25"/>
				</Grid>
			</controls:PivotItem>
    	</controls:Pivot>
        <!--<adduplex:AdControl AppId="2951" 
                            IsTest="False" 
                            Margin="0,5,8,0" 
                            d:LayoutOverrides="HorizontalMargin" 
                            VerticalAlignment="Bottom" 
                            BackgroundOpacity="0"/>-->
        <adRotator:AdRotatorControl x:Name="adRotatorControl"
                                    SettingsUrl="http://dev.scottisafool.co.uk/files/wp7/AdRotatorSupporterFile.xml"
                                    DefaultAdType="PubCenter"
                                    DefaultSettingsFileUri="/WebTone;component/AdRotatorSupporterFile.xml"
                                    AdDuplexAppId="2951"
                                    PubCenterAdUnitId="10027004"
                                    PubCenterAppId="0e79c4c8-5c19-45e2-88ff-3eedc5b0831c"
                                    Width="480"
                                    Height="80"
                                    VerticalAlignment="Bottom"/>                                    
                                    
        <scott:ErrorBox x:Name="errorMessageBox" 
                        VerticalAlignment="Top" 
                        Margin="0"/>
		
    </Grid>
    
    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton Text="play" 
                                            IconUri="/Icons/appbar.transport.play.rest.png" 
                                            x:Name="btnPlayPause" 
                                            Click="btnPlayPause_Click"/>
            <shell:ApplicationBarIconButton IconUri="/Icons/appbar.saveringtone.rest.png" 
                                            Text="save" 
                                            x:Name="btnSave" 
                                            IsEnabled="False" 
                                            Click="btnSave_Click"/>
            <shell:ApplicationBarIconButton Text="browse"
                                            IconUri="/Icons/appbar.ie.rest.png"
                                            x:Name="btnBrowse"
                                            Click="btnBrowse_Click"/>
            <shell:ApplicationBarIconButton Text="favourites"
                                            x:Name="btnFavourties"
                                            IconUri="/Icons/appbar.favs.rest.png"
                                            Click="btnFavourties_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="menuSettings" 
                                              Text="settings" 
                                              Click="menuSettings_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>